//
//  ServiceCenterViewController.m
//  LocomotiveGuards
//
//  Created by zwj on 15-11-30.
//  Copyright (c) 2015年 REDOOR. All rights reserved.
//

#import "ServiceCenterViewController.h"
#import "CustomCell.h"
#import "PopLoadMsg.h"
#import "PopMsg.h"
#import "SearchAreas.h"
#import "CustomDailButton.h"
#import "LoginViewController.h"
#import "AlertView.h"

@interface ServiceCenterViewController () <UITableViewDelegate,UITableViewDataSource,UIPickerViewDataSource,UIPickerViewDelegate>
{
    SearchAreas *_searchArea;
    UILabel *_phoneContentLabel;
    UILabel *_timeContentLabel;
    UILabel *_insuranceTelLabel;
    NSString *_telephone;
    UILabel *_provinceLabel;
    UILabel *_cityLabel;
    UIButton *_districtBtn;
    UITableView *_tableView;
    NSString *_serviceTime;
    NSString *_insuranceTel;
    NSDictionary *_userListDic;
    NSMutableArray *_serviceListArr;
    NSArray *_districtArray;
    UIView *_maskView;
    UIView *_alertView;
    UIPickerView *_distPicker;
    NSInteger _flag;//标记哪行cell被点击
}
@property (nonatomic, strong) NSString *userOrTourist;
@property (nonatomic, strong) UIButton *callInsuranceBtn;
@property (nonatomic, strong) UIButton *callBtn;
@property (nonatomic, strong) UILabel *alertLabel;

@end

@implementation ServiceCenterViewController
- (instancetype)init {
    self = [super init];
    if (self) {
        _searchArea = [[SearchAreas alloc] init];
        _serviceListArr = [NSMutableArray array];
        _flag = 0;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.userOrTourist = [[NSUserDefaults standardUserDefaults] objectForKey:@"userOrTourist"];

    [self createMyNav];
    [self configView];
    [self getOfficialCSInfoRequest];
}

- (void)createMyNav
{
    [self addTitle:@"服务中心" imageName:@"serviceconter"];
    [self addBackBtnTarget:self action:@selector(backBtnClick)];
}

- (void)configView
{
    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 20+44*H, SCREEN_WIDTH, 125*H)];
    bgView.backgroundColor = [UIColor colorWithRed:247.f/255.f green:248.f/255.f blue:248.f/255.f alpha:1.0f];
    
    UILabel *phoneLabel = [self createLabelFrame:CGRectMake(20*W, 15*H, 90*W, 40*H) title:@"007机车卫士\n客服电话" font:[UIFont systemFontOfSize:14]];
    phoneLabel.textColor = [UIColor grayColor];
    phoneLabel.textAlignment = NSTextAlignmentLeft;
    phoneLabel.numberOfLines = 2;
    [bgView addSubview:phoneLabel];
    
    _phoneContentLabel = [self createLabelFrame:CGRectMake(120*W, 25*H, 105*W, 20*H) title:nil font:[UIFont systemFontOfSize:13]];
    _phoneContentLabel.textColor = [UIColor grayColor];
    _phoneContentLabel.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:_phoneContentLabel];
    
    UILabel *timeLabel = [self createLabelFrame:CGRectMake(20*W, 65*H, 90*W, 20*H) title:@"服务时间" font:[UIFont systemFontOfSize:14]];
    timeLabel.textColor = [UIColor grayColor];
    timeLabel.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:timeLabel];
    
    _timeContentLabel = [self createLabelFrame:CGRectMake(120*W, 65*H, 105*W, 20*H) title:nil font:[UIFont systemFontOfSize:13]];
    _timeContentLabel.textColor = [UIColor grayColor];
    _timeContentLabel.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:_timeContentLabel];
    
    UILabel *insuranceLabel = [self createLabelFrame:CGRectMake(20*W, 90*H, 90*W, 20*H) title:@"保险联系电话" font:[UIFont systemFontOfSize:13]];
    insuranceLabel.textColor = [UIColor grayColor];
    insuranceLabel.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:insuranceLabel];
    
    _insuranceTelLabel = [self createLabelFrame:CGRectMake(120*W, 90*H, 105*W, 20*H) title:nil font:[UIFont systemFontOfSize:13]];
    _insuranceTelLabel.textColor = [UIColor grayColor];
    _insuranceTelLabel.textAlignment = NSTextAlignmentLeft;
    [bgView addSubview:_insuranceTelLabel];
    
    self.callBtn = [self createBtnFrame:CGRectMake(230*W, (100*H-24*H)/2, 70*W, 24*H) title:nil bgImageName:@"dial" selectedImageName:@"dial_on" target:self action:@selector(btnDialCS)];
    [bgView addSubview:self.callBtn];
    [self.view addSubview:bgView];
    
    self.callInsuranceBtn = [self createBtnFrame:CGRectMake(230*W, 90*H, 70*W, 24*H) title:nil bgImageName:@"dial" selectedImageName:@"dial_on" target:self action:@selector(insuranceBtnClick)];
    [bgView addSubview:self.callInsuranceBtn];
    [self.view addSubview:bgView];
    
    UILabel *tipLabel = [self createLabelFrame:CGRectMake(20*W, CGRectGetMaxY(bgView.frame), SCREEN_WIDTH-40*W, 40*H) title:@"若您需要更换电话号码或设备，或进行相关资讯，预约登记，维修解锁，请点击“拨打号码”按钮" font:[UIFont systemFontOfSize:12]];
    tipLabel.textColor = [UIColor grayColor];
    tipLabel.textAlignment = NSTextAlignmentLeft;
    tipLabel.numberOfLines = 0;
    [self.view addSubview:tipLabel];
    
    UILabel *serviceLabel = [self createLabelFrame:CGRectMake(20*W, CGRectGetMaxY(tipLabel.frame)+10*H, 90*W, 30*H) title:@"电动车服务站" font:[UIFont boldSystemFontOfSize:15]];
    serviceLabel.textColor = [UIColor grayColor];
    serviceLabel.textAlignment = NSTextAlignmentLeft;
    [self.view addSubview:serviceLabel];
    
    _provinceLabel = [self createLabelFrame:CGRectMake(120*W, CGRectGetMaxY(tipLabel.frame)+12*H, 55*W, 25*H) title:@"" font:[UIFont systemFontOfSize:13]];
    _provinceLabel.textColor = [UIColor grayColor];
    [self.view addSubview:_provinceLabel];
    
    _cityLabel = [self createLabelFrame:CGRectMake(178*W, CGRectGetMaxY(tipLabel.frame)+12*H, 55*W, 25*H) title:@"" font:[UIFont systemFontOfSize:13]];
    _cityLabel.textColor = [UIColor grayColor];
    [self.view addSubview:_cityLabel];
    
    _districtBtn = [self createBtnFrame:CGRectMake(236*W, CGRectGetMaxY(tipLabel.frame)+11*H, 60*W, 27*H) title:@"" bgImageName:@"address" selectedImageName:@"address" target:self action:@selector(selectDistrict)];
    [_districtBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    _districtBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [self.view addSubview:_districtBtn];
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_districtBtn.frame)+10*H, SCREEN_WIDTH, SCREEN_HEIGHT-CGRectGetMaxY(_districtBtn.frame)-TABBAR_HEIGHT-10*H) style:UITableViewStylePlain];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = [UIColor colorWithRed:247.f/255.f green:248.f/255.f blue:248.f/255.f alpha:1.0f];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
}

- (void)reloadView
{
    if (!_userListDic) {
        return;
    }
    _phoneContentLabel.text = _telephone;
    _timeContentLabel.text = _serviceTime;
    _insuranceTelLabel.text = _insuranceTel;
    _provinceLabel.text = [_userListDic objectForKey:@"province"];
    _cityLabel.text = [_userListDic objectForKey:@"city"];
    [_districtBtn setTitle:[[_userListDic objectForKey:@"district"] stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" "]] forState:UIControlStateNormal];
}

// 若请求没有响应的服务器，提示此信息
- (void)addNoResultView {
    
    self.alertLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(_districtBtn.frame)+30*H, SCREEN_WIDTH, 30)];
    self.alertLabel.backgroundColor = [UIColor whiteColor];
    self.alertLabel.text = @"此区域暂无合作点，请您就近选择其他区域";
    self.alertLabel.font = [UIFont systemFontOfSize:13.0];
    self.alertLabel.textAlignment = NSTextAlignmentCenter;
    self.alertLabel.textColor = [UIColor lightGrayColor];
    [self.view addSubview:self.alertLabel];
}

- (UIPickerView *)showAlertWithIndex:(NSInteger)index
{
    _maskView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT)];
    _maskView.backgroundColor = [UIColor colorWithRed:100.f/255.f green:100.f/255.f blue:100.f/255.f alpha:0.5f];
    
    _alertView = [[UIView alloc] initWithFrame:CGRectMake(50*W, 170*H, SCREEN_WIDTH-100*W, 300*H)];
    _alertView.backgroundColor = [UIColor whiteColor];
    _alertView.layer.cornerRadius = 10;
    
    UILabel *alertLabel = [self createLabelFrame:CGRectMake((CGRectGetWidth(_alertView.frame)-100*W)/2, 10*H, 100*W, 30*H) title:@"选择地区" font:[UIFont systemFontOfSize:18]];
    alertLabel.textColor = [UIColor grayColor];
    [_alertView addSubview:alertLabel];
    
    UIButton *cancelBtn = [self createBtnFrame:CGRectMake(0, CGRectGetHeight(_alertView.frame)-35*H+1, (CGRectGetWidth(_alertView.frame)-1)/2, 35*H-1) title:@"取消" bgImageName:nil selectedImageName:nil target:self action:@selector(cancelBtnClicked:)];
    cancelBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [cancelBtn setTitleColor:[UIColor colorWithRed:(CGFloat)45/255 green:(CGFloat)143/255 blue:(CGFloat)247/255 alpha:1.0] forState:UIControlStateNormal];
    [_alertView addSubview:cancelBtn];
    
    UILabel *horiLabel = [self createLabelFrame:CGRectMake(0, CGRectGetHeight(_alertView.frame)-35*H, CGRectGetWidth(_alertView.frame), 1) title:nil font:nil];
    horiLabel.backgroundColor = [UIColor grayColor];
    [_alertView addSubview:horiLabel];
    
    UILabel *verLabel = [self createLabelFrame:CGRectMake((CGRectGetWidth(_alertView.frame)-1)/2, CGRectGetHeight(_alertView.frame)-35*H, 1, 35*H) title:nil font:nil];
    verLabel.backgroundColor = [UIColor grayColor];
    [_alertView addSubview:verLabel];
    
    UIButton *confirmBtn = [self createBtnFrame:CGRectMake((CGRectGetWidth(_alertView.frame)+1)/2, CGRectGetHeight(_alertView.frame)-35*H+1, (CGRectGetWidth(_alertView.frame)-1)/2, 35*H-1) title:@"确定" bgImageName:nil selectedImageName:nil target:self action:@selector(confirmBtnClicked:)];
    confirmBtn.tag = index;
    confirmBtn.titleLabel.font = [UIFont systemFontOfSize:18];
    [confirmBtn setTitleColor:[UIColor colorWithRed:(CGFloat)45/255 green:(CGFloat)143/255 blue:(CGFloat)247/255 alpha:1.0] forState:UIControlStateNormal];
    [_alertView addSubview:confirmBtn];
    
    UIPickerView *pickerView = [UIPickerView new];
    CALayer *viewLayer = pickerView.layer;
    [viewLayer setFrame:CGRectMake(30*W, 40*H, CGRectGetWidth(_alertView.frame)-60*W, CGRectGetHeight(_alertView.frame)-90*H)];
    [_alertView addSubview:pickerView];
    [_maskView addSubview:_alertView];
    [self.view addSubview:_maskView];
    return pickerView;
}


#pragma mark - 网络请求
//获取官方客服信息请求
- (void)getOfficialCSInfoRequest
{
    PopLoadMsg *loadmsg = [PopLoadMsg new];
    [loadmsg delayLoadImages];
    
    NSDictionary *paramdic = @{@"loginId":[[NSUserDefaults standardUserDefaults] objectForKey:@"phonenumber"]};
    NSString *url = [urlstring stringByAppendingString:@"getOfficialCSInfo.do"];
    
    [K_AppDelegate GenerateHTTPRequestWithUrl:url withParam:paramdic success:^(AFHTTPRequestOperation *op,id responseObject){
        [loadmsg delayImagesRemove];
        NSDictionary *dic = (NSDictionary *)responseObject;
        NSLog(@"OfficialCS-dic = %@", dic);
        NSString *msg = [dic objectForKey:@"msg"];
        NSInteger flag = [[dic objectForKey:@"flag"] integerValue];
        _telephone = [dic objectForKey:@"telephone"];
        _serviceTime = [dic objectForKey:@"serviceTime"];
        _insuranceTel = [dic objectForKey:@"insuranceTel"];
        if (flag == 0) {
            _phoneContentLabel.text = _telephone;
            _timeContentLabel.text = _serviceTime;
            _insuranceTelLabel.text = _insuranceTel;
            if (_insuranceTel.length == 0) {
                [self.callInsuranceBtn setImage:[UIImage imageNamed:@"phone-no1"] forState:UIControlStateNormal];
                self.callInsuranceBtn.enabled = NO;
            }
            else {
                [self.callInsuranceBtn setImage:[UIImage imageNamed:@"dial"] forState:UIControlStateNormal];
                self.callInsuranceBtn.enabled = YES;
            }
            if (_telephone.length == 0) {
                [self.callBtn setImage:[UIImage imageNamed:@"phone-no1"] forState:UIControlStateNormal];
                self.callBtn.enabled = NO;
            }
            else {
                [self.callBtn setImage:[UIImage imageNamed:@"dial"] forState:UIControlStateNormal];
                self.callBtn.enabled = YES;
            }
            [self getUserInfoRequest];
            
        }
        else {
            [PopMsg showMessage:msg Lasttime:1.0f];
        }
        
    }failure:^(AFHTTPRequestOperation *op,NSError *error){
        [loadmsg delayImagesRemove];
        [PopMsg showMessage:@"网络异常，请重试" Lasttime:1.0f];
    }];
}

//查询用户信息（获取用户所属区域）
- (void)getUserInfoRequest
{
    PopLoadMsg *loadmsg = [PopLoadMsg new];
    [loadmsg delayLoadImages];
    
    NSDictionary *paramdic = @{@"loginId":[[NSUserDefaults standardUserDefaults] objectForKey:@"phonenumber"]};
    NSString *url = [urlstring stringByAppendingString:@"getUserInfo.do"];
    
    [K_AppDelegate GenerateHTTPRequestWithUrl:url withParam:paramdic success:^(AFHTTPRequestOperation *op,id responseObject){
        [loadmsg delayImagesRemove];
        NSDictionary *dic = (NSDictionary *)responseObject;
        NSLog(@"UserInfo-dic = %@", dic);
        NSInteger flag = [[dic objectForKey:@"flag"] integerValue];
        if (flag == 0) {
            _userListDic = dic;
            [self reloadView];
            [self getLocalCSInfoRequest];
        }
        
    }failure:^(AFHTTPRequestOperation *op,NSError *error){
        [loadmsg delayImagesRemove];
        [PopMsg showMessage:@"网络异常，请重试" Lasttime:1.0f];
    }];
}

//获取各服务点客服请求
- (void)getLocalCSInfoRequest
{
    if (!_userListDic) {
        return;
    }
    //请求前先清空上一次数据
    [_serviceListArr removeAllObjects];
    
    PopLoadMsg *loadmsg = [PopLoadMsg new];
    [loadmsg delayLoadImages];
    
    NSDictionary *paramdic = @{@"loginId":[[NSUserDefaults standardUserDefaults] objectForKey:@"phonenumber"],
                             @"province":[_userListDic objectForKey:@"province"],
                             @"city":[_userListDic objectForKey:@"city"],
                             @"district":_districtBtn.currentTitle};
    NSString *url = [urlstring stringByAppendingString:@"getLocalCSInfo.do"];
    __weak __typeof(self) weakSelf = self;
    [K_AppDelegate GenerateHTTPRequestWithUrl:url withParam:paramdic success:^(AFHTTPRequestOperation *op,id responseObject){
        [loadmsg delayImagesRemove];
        NSDictionary *dic = (NSDictionary *)responseObject;
        NSLog(@"LocalCS-dic = %@", dic);
        NSInteger flag = [[dic objectForKey:@"flag"] integerValue];
        NSString *msg = [dic objectForKey:@"msg"];
        _serviceListArr = [[dic objectForKey:@"serviceLists"] mutableCopy];
        [_tableView reloadData];
        if (flag == 0) {
            NSLog(@"success!");
            [weakSelf.alertLabel removeFromSuperview];

        }
        else {
            [PopMsg showMessage:msg Lasttime:1.0f];
            if (_serviceListArr.count == 0) {
                [weakSelf addNoResultView];
            }
        }
        
    }failure:^(AFHTTPRequestOperation *op,NSError *error){
        [loadmsg delayImagesRemove];
        [PopMsg showMessage:@"网络异常，请重试" Lasttime:1.0f];
    }];
}

#pragma mark - 点击事件
//返回按钮
- (void)backBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

//拨打客服电话
- (void)btnDialCS
{
    if ([self.userOrTourist isEqualToString:@"1"]) {
        if (_phoneContentLabel.text && ![_phoneContentLabel.text isEqualToString:@""]) {
            NSString *num = [[NSString alloc] initWithFormat:@"tel://%@",_phoneContentLabel.text];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]];//拨号
        }else {
            return;
        }
    }
    else {
        
        AlertView *alertView = [[AlertView alloc] initWithConfirmButtonBlock:^{
            NSLog(@"登录");
            LoginViewController *loginVC = [[LoginViewController alloc]init];
            [self presentViewController:loginVC animated:YES completion:nil];
        } cancelButtonBlock:^{
            NSLog(@"取消");
        }];
        [self.view addSubview:alertView];
    }
}

// 拨打保险电话
- (void)insuranceBtnClick {

    if ([self.userOrTourist isEqualToString:@"1"]) {
        if (_insuranceTelLabel.text && ![_insuranceTelLabel.text isEqualToString:@""]) {
            NSString *num = [[NSString alloc] initWithFormat:@"tel://%@",_phoneContentLabel.text];
            [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]];//拨号
        }else {
            return;
        }
    }
    else {
        
        AlertView *alertView = [[AlertView alloc] initWithConfirmButtonBlock:^{
            NSLog(@"登录");
            LoginViewController *loginVC = [[LoginViewController alloc]init];
            [self presentViewController:loginVC animated:YES completion:nil];
        } cancelButtonBlock:^{
            NSLog(@"取消");
        }];
        [self.view addSubview:alertView];
    }
}

//拨打专卖店电话
- (void)btnDialLocal:(CustomDailButton *)btn
{
    NSString *phoneStr = [_serviceListArr[btn.tag-10] objectForKey:@"phone"];
    if (phoneStr && ![phoneStr isEqualToString:@""]) {
        NSString *num = [[NSString alloc] initWithFormat:@"tel://%@",phoneStr];
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]];//拨号
        [btn setOn:YES];
    }else {
        return;
    }
}

//切换区域
- (void)selectDistrict{
    if ([self.userOrTourist isEqualToString:@"1"]) {
        if (_provinceLabel.text.length > 0 && _cityLabel.text.length > 0) {
            _districtArray = [_searchArea returnDistrictsWithProvince:_provinceLabel.text City:_cityLabel.text];
            _distPicker = [self showAlertWithIndex:102];
            _distPicker.delegate = self;
            _distPicker.dataSource = self;
            for (NSInteger i=0; i<_districtArray.count; i++) {
                if ([_districtArray[i] isEqualToString:_districtBtn.currentTitle]) {
                    [_distPicker selectRow:i inComponent:0 animated:NO];
                    break;
                }
                else {
                    [_distPicker selectRow:_districtArray.count/2 inComponent:0 animated:NO];
                }
            }
        }
        else {
            return;
        }
    }
    else {
    
        AlertView *alertView = [[AlertView alloc] initWithConfirmButtonBlock:^{
            NSLog(@"登录");
            LoginViewController *loginVC = [[LoginViewController alloc]init];
            [self presentViewController:loginVC animated:YES completion:nil];
        } cancelButtonBlock:^{
            NSLog(@"取消");
        }];
        [self.view addSubview:alertView];
    }
}

//alertView的取消按钮点击事件
- (void)cancelBtnClicked:(UIButton *)btn
{
    [_alertView removeFromSuperview];
    _alertView = nil;
    [_maskView removeFromSuperview];
    _maskView = nil;
}

//alertView的确定按钮点击事件
- (void)confirmBtnClicked:(UIButton *)btn
{
    if (btn.tag == 102) {
        NSInteger num = [_distPicker selectedRowInComponent:0];
        NSString *district = _districtArray[num];
        [_districtBtn setTitle:district forState:UIControlStateNormal];
        [self getLocalCSInfoRequest];
    }
    [_alertView removeFromSuperview];
    _alertView = nil;
    [_maskView removeFromSuperview];
    _maskView = nil;
}

#pragma mark - UITableView代理
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _serviceListArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellID = @"cell";
    CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    
    cell.shopLabel.text = [_serviceListArr[indexPath.row] objectForKey:@"name"];
    cell.addressLabel.text = [_serviceListArr[indexPath.row] objectForKey:@"adress"];
    cell.phoneLabel.text = [NSString stringWithFormat:@"电话：%@",[_serviceListArr[indexPath.row] objectForKey:@"phone"]];
    [cell.leftImageView setImage:[UIImage imageNamed:@"service_pic_photo"]];
    cell.separatorLine.backgroundColor = [UIColor colorWithRed:230.f/255.f green:230.f/255.f blue:230.f/255.f alpha:1.0f];
    
    if ([cell viewWithTag:1000]) {
         [[cell viewWithTag:1000] removeFromSuperview];
    }
    
    if (indexPath.row == _flag-10) {
        UIView *dailBgView = [[UIView alloc] initWithFrame:CGRectMake(0, 70*H, SCREEN_WIDTH, 30*H)];
        dailBgView.backgroundColor = [UIColor whiteColor];
        CustomDailButton *dailBtn = [[CustomDailButton alloc] initWithFrame:CGRectMake((SCREEN_WIDTH-100*W)/2, 0, 104*W, 30*H)];
        dailBtn.tag = _flag;
        [dailBtn setOn:NO];
        [dailBtn addTarget:self action:@selector(btnDialLocal:) forControlEvents:UIControlEventTouchUpInside];
        [dailBgView addSubview:dailBtn];
        dailBgView.tag = 1000;
        [cell.contentView addSubview:dailBgView];
        
        UILabel *newSeparatorLine = [[UILabel alloc] initWithFrame:CGRectMake(0, 29*H, SCREEN_WIDTH, 1)];
        newSeparatorLine.backgroundColor = [UIColor colorWithRed:230.f/255.f green:230.f/255.f blue:230.f/255.f alpha:1.0f];
        [dailBgView addSubview:newSeparatorLine];
        cell.separatorLine.backgroundColor = [UIColor clearColor];
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == _flag-10) {
        return 100*H;
    }
    else {
        return 70*H;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([self.userOrTourist isEqualToString:@"1"]) {
        if (_flag == indexPath.row+10) {
            _flag = 0;
        }
        else {
            _flag = indexPath.row+10;
        }
        [_tableView reloadData];
    }
    else {
        AlertView *alertView = [[AlertView alloc] initWithConfirmButtonBlock:^{
            NSLog(@"登录");
            LoginViewController *loginVC = [[LoginViewController alloc]init];
            [self presentViewController:loginVC animated:YES completion:nil];
        } cancelButtonBlock:^{
            NSLog(@"取消");
        }];
        [self.view addSubview:alertView];
    }
}

#pragma mark- UIPickerView代理函数
//行数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return _districtArray.count;
}

//一共多少列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 30;
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
    UILabel *pickerLabel = (UILabel *)view;
    if (pickerView == _distPicker) {
        if (!pickerLabel) {
            pickerLabel = [UILabel new];
            pickerLabel.text = _districtArray[row];
            pickerLabel.textAlignment = NSTextAlignmentCenter;
            pickerLabel.textColor = [UIColor blackColor];
        }
    }
    return pickerLabel;
}

#pragma mark -
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
